// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>

struct data
{
	int a, b, dis;
};

typedef std::pair<int, int> pair;
std::queue<data> q;
std::set<pair> vis;
int a, b;

void work(int a, int b, int d)
{
	int ta = a, tb = b;
	if (!(a & 1)) {
		a /= 2;
		if (a > b) std::swap(a, b);
		pair tmp(a, b);
		if (vis.find(tmp) == vis.end()) {
			vis.insert(tmp);
			data tt; tt.a = a; tt.b = b; tt.dis = d + 1;
			q.push(tt);
		}
	}
	a = ta; b = tb;
	if (!(a % 3)) {
		a /= 3;
		if (a > b) std::swap(a, b);
		pair tmp(a, b);
		if (vis.find(tmp) == vis.end()) {
			vis.insert(tmp);
			data tt; tt.a = a; tt.b = b; tt.dis = d + 1;
			q.push(tt);
		}
	}
	a = ta; b = tb;
	if (!(a % 5)) {
		a /= 5;
		if (a > b) std::swap(a, b);
		pair tmp(a, b);
		if (vis.find(tmp) == vis.end()) {
			vis.insert(tmp);
			data tt; tt.a = a; tt.b = b; tt.dis = d + 1;
			q.push(tt);
		}
	}
}

int main()
{
	std::cin >> a >> b;
	if (a > b) std::swap(a, b);
	data tmp; tmp.a = a; tmp.b = b; tmp.dis = 0;
	q.push(tmp);
	vis.insert(std::make_pair(a, b));
	bool ok = false;
	for (int i = 0; i < 4000000 && !q.empty(); i++) {
		data now = q.front(); q.pop();
//		std::cout << now.a << " " << now.b << " " << now.dis << "\n";
		if (now.a == now.b) { std::cout << now.dis << "\n"; ok = true; break; }
		work(now.a, now.b, now.dis);
		work(now.b, now.a, now.dis);
	}
	if (!ok) std::cout << "-1\n";
}

